program B;

{$APPTYPE CONSOLE}

{uses
  SysUtils; }
var
  a1, b1, q1, a2, b2, q2, c, i, t1, t2, t3, l, d: Comp;

function cdiv(m,n:Comp):Comp;
begin
  result := Trunc(m / n);
end;

function cmod(m,n:Comp):Comp;
begin
  Result := m - cdiv(m, n) * n
end;

function gcd(m,n:Comp):Comp;
begin
  if n = 0  then
   gcd:=m
  else
   gcd:=gcd(n, cmod(m, n));
end;

function lcm(m,n:Comp):Comp;
begin
  lcm:=cdiv(m*n, gcd(m,n));
end;

begin
  //try
    readln(a1, b1, q1, a2, b2, q2);
    if (a2 > b1) or (a1 > b2) then begin
      writeln(0);
      //readln;
      Exit;
    end;
    if (a2 = b1) or (a1 = b2) then begin
      writeln(1);
      //readln;
      Exit;
    end;
    if (a1 > a2) then begin
      t1 := a1;
      t2 := b1;
      t3 := q1;
      a1 := a2;
      b1 := b2;
      q1 := q2;
      a2 := t1;
      b2 := t2;
      q2 := t3;
    end;
    l := lcm(q1, q2);
    d := b1 - a2;
    if cmod(d, l) > 0 then
       writeln(cdiv(d, l) + 1:0:0)
    else
       writeln(cdiv(d, l) + 1:0:0);

    //max
    //for I := 0 to List.Count - 1 do

    //writeln(lcm(q1, q2));
    //readln;
    { TODO -oUser -cConsole Main : Insert code here }
  {except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;  }
end.
